<?php


namespace ApplicationTest\Model;

use Logger;
use Model\Factory\TableGatewayFactory;
use Model\UserTable;
use PHPUnit_Framework_TestCase;
use ApplicationTest\TestBootstrap;


include __DIR__.'/../../TestBootstrap.php';


class UserTableTest extends PHPUnit_Framework_TestCase
{

    /**
     * @var UserTable
     */
    protected  $userTable;
    protected function setUp()
    {

        $serviceManager =  TestBootstrap::getServiceManager();
        $this->userTable =  $serviceManager->get('Model\UserTable');
//        $this->userTable = TableGatewayFactory::getUserTable();

    }

    public function testInsertUser(){
        $int = $this->userTable->insert(array('username'=>'operator', 'password'=>'secret'));
        $insertedUser = $this->userTable->getUser($int);
        $this->assertEquals('operator', $insertedUser->username);
        $this->userTable->delete($int);
    }

    public function testInjectCreatedByUser(){
        $int = $this->userTable->insert(array('username'=>'operator', 'password'=>'secret'));
        $insertedUser = $this->userTable->getUser($int);
        $this->assertEquals(100, $insertedUser->created_by);
//        $this->userTable->delete($int);
    }

    public function testGetAllRole(){
        $user = $this->userTable->getUserByName('admin');
        $resultSetInterface = $user->getAllRole();
        foreach ($resultSetInterface as $aRole) {
            Logger::debug($aRole->name);
        }

    }



}